home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Morphos / GCC / ppc-amigaos / include / sys / time.h < prev    next >
C/C++ Source or Header  |  1997-09-16  |  5KB  |  161 lines

  1. /*    $NetBSD: time.h,v 1.16 1995/06/15 23:08:11 cgd Exp $    */
  2.  
  3. /*
  4.  * Copyright (c) 1982, 1986, 1993
  5.  *    The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  *    This product includes software developed by the University of
  18.  *    California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  *    @(#)time.h    8.2 (Berkeley) 7/10/94
  36.  */
  37.  
  38. #ifndef _SYS_TIME_H_
  39. #define _SYS_TIME_H_
  40.  
  41. #include <sys/types.h>
  42.  
  43. /*
  44.  * Structure returned by gettimeofday(2) system call,
  45.  * and used in other calls.
  46.  */
  47. #ifndef DEVICES_TIMER_H
  48. /* Use whatever was included first, standard or Amiga (devices/timer.h)
  49.  * includes (jch). */
  50. struct timeval {
  51.     long    tv_sec;        /* seconds */
  52.     long    tv_usec;    /* and microseconds */
  53. };
  54. #else
  55. #define tv_sec  tv_secs
  56. #define tv_usec tv_micro
  57. #endif
  58.  
  59. /*
  60.  * Structure defined by POSIX.4 to be like a timeval.
  61.  */
  62. struct timespec {
  63.     time_t    ts_sec;        /* seconds */
  64.     long    ts_nsec;    /* and nanoseconds */
  65. };
  66.  
  67. #define    TIMEVAL_TO_TIMESPEC(tv, ts) {                    \
  68.     (ts)->ts_sec = (tv)->tv_sec;                    \
  69.     (ts)->ts_nsec = (tv)->tv_usec * 1000;                \
  70. }
  71. #define    TIMESPEC_TO_TIMEVAL(tv, ts) {                    \
  72.     (tv)->tv_sec = (ts)->ts_sec;                    \
  73.     (tv)->tv_usec = (ts)->ts_nsec / 1000;                \
  74. }
  75.  
  76. struct timezone {
  77.     int    tz_minuteswest;    /* minutes west of Greenwich */
  78.     int    tz_dsttime;    /* type of dst correction */
  79. };
  80. #define    DST_NONE    0    /* not on dst */
  81. #define    DST_USA        1    /* USA style dst */
  82. #define    DST_AUST    2    /* Australian style dst */
  83. #define    DST_WET        3    /* Western European dst */
  84. #define    DST_MET        4    /* Middle European dst */
  85. #define    DST_EET        5    /* Eastern European dst */
  86. #define    DST_CAN        6    /* Canada */
  87.  
  88. /* Operations on timevals. */
  89. #define    timerclear(tvp)        (tvp)->tv_sec = (tvp)->tv_usec = 0
  90. #define    timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  91. #define    timercmp(tvp, uvp, cmp)                        \
  92.     (((tvp)->tv_sec == (uvp)->tv_sec) ?                \
  93.         ((tvp)->tv_usec cmp (uvp)->tv_usec) :            \
  94.         ((tvp)->tv_sec cmp (uvp)->tv_sec))
  95. #define    timeradd(tvp, uvp, vvp)                        \
  96.     do {                                \
  97.         (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;        \
  98.         (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;    \
  99.         if ((vvp)->tv_usec >= 1000000) {            \
  100.             (vvp)->tv_sec++;                \
  101.             (vvp)->tv_usec -= 1000000;            \
  102.         }                            \
  103.     } while (0)
  104. #define    timersub(tvp, uvp, vvp)                        \
  105.     do {                                \
  106.         (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;        \
  107.         (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;    \
  108.         if ((vvp)->tv_usec < 0) {                \
  109.             (vvp)->tv_sec--;                \
  110.             (vvp)->tv_usec += 1000000;            \
  111.         }                            \
  112.     } while (0)
  113.  
  114. /*
  115.  * Names of the interval timers, and structure
  116.  * defining a timer setting.
  117.  */
  118. #define    ITIMER_REAL    0
  119. #define    ITIMER_VIRTUAL    1
  120. #define    ITIMER_PROF    2
  121.  
  122. struct    itimerval {
  123.     struct    timeval it_interval;    /* timer interval */
  124.     struct    timeval it_value;    /* current value */
  125. };
  126.  
  127. /*
  128.  * Getkerninfo clock information structure
  129.  */
  130. struct clockinfo {
  131.     int    hz;        /* clock frequency */
  132.     int    tick;        /* micro-seconds per hz tick */
  133.     int    tickadj;    /* clock skew rate for adjtime() */
  134.     int    stathz;        /* statistics clock frequency */
  135.     int    profhz;        /* profiling clock frequency */
  136. };
  137.  
  138. #ifdef _KERNEL
  139. int    itimerfix __P((struct timeval *tv));
  140. int    itimerdecr __P((struct itimerval *itp, int usec));
  141. void    microtime __P((struct timeval *tv));
  142. #else /* !_KERNEL */
  143. #include <time.h>
  144.  
  145. #ifndef _POSIX_SOURCE
  146. #include <sys/cdefs.h>
  147.  
  148. __BEGIN_DECLS
  149. int    adjtime __P((const struct timeval *, struct timeval *));
  150. int    getitimer __P((int, struct itimerval *));
  151. int    gettimeofday __P((struct timeval *, struct timezone *));
  152. int    setitimer __P((int, const struct itimerval *, struct itimerval *));
  153. int    settimeofday __P((const struct timeval *, const struct timezone *));
  154. int    utimes __P((const char *, const struct timeval *));
  155. __END_DECLS
  156. #endif /* !POSIX */
  157.  
  158. #endif /* !_KERNEL */
  159.  
  160. #endif /* !_SYS_TIME_H_ */
  161.